/**
 * @author sen
 * @date 2020/2/4 11:05
 * 7. 整数反转
 */
public class ReverseInt {

    public static void main(String[] args){
        System.out.println(reverse(1469087856));
    }

    public static int reverse(int x) {
        int res = 0;
        while (x != 0){
            int pop = x % 10;
            if (res>Integer.MAX_VALUE/10||(res==Integer.MAX_VALUE/10)&&(pop>7)){
                return 0;
            }
            if (res<Integer.MIN_VALUE/10||(res==Integer.MIN_VALUE/10&&(pop<-8))){
                return 0;
            }
            res = res * 10 + pop;
            x /= 10;
        }
        return res;
    }

}
